home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
netprog.zip
/
NETPROG.TAR
/
lock
/
lockcreat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-12-17
|
608b
|
37 lines
/*
* Locking routines using a creat() system call with all
* permissions turned off.
*/
#include <sys/errno.h>
extern int errno;
#define LOCKFILE "seqno.lock"
#define TEMPLOCK "temp.lock"
my_lock(fd)
int fd;
{
int tempfd;
/*
* Try to create a temporary file, with all write
* permissions turned off. If the temporary file already
* exists, the creat() will fail.
*/
while ( (tempfd = creat(TEMPLOCK, 0)) < 0) {
if (errno != EACCES)
err_sys("creat error");
sleep(1);
}
close(tempfd);
}
my_unlock(fd)
int fd;
{
if (unlink(TEMPLOCK) < 0)
err_sys("unlink error for tempfile");
}